package com.bankoption.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtil {
	/**
	/**
	 * 通过网站域名URL,网页编码获取该网站的源码
	 * 
	 * @param url
	 * @return String
	 * @throws Exception
	 */
	public static String getHTML(String pageURL, String encoding) {
		StringBuilder pageHTML = new StringBuilder();
		try {
			URL url = new URL(pageURL);
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			if(connection!=null){
				connection.setRequestProperty("User-Agent",
								"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/533.3 (KHTML, like Gecko) Chrome/5.0.354.0 Safari/533.3");
				BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));
				String line = null;
				while ((line = br.readLine()) != null) {
					pageHTML.append(line);
					pageHTML.append("\r\n");
				}
				br.close();
			}
			 connection.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageHTML.toString();
	}

}
